package com.epam.training.domain;

import java.io.Serializable;

import javax.persistence.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * The persistent class for the bonus database table.
 * 
 */
@Entity
@Table(name = "bonus")
@NamedQuery(name = "Bonus.findAll", query = "SELECT b FROM Bonus b")
public class Bonus implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name = "BONUS_BONUSID_GENERATOR", sequenceName = "BONUS_ID_SEQ", initialValue = 1, allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BONUS_BONUSID_GENERATOR")
	@Column(name = "bonus_id", insertable = false, updatable = false, unique = true, nullable = false)
	private Integer bonusId;

	@Column(precision = 131089)
	private BigDecimal amount;

	@Column(length = 2147483647)
	private String description;

	@Column(length = 30)
	private String name;

	// bi-directional many-to-one association to Paymant
	@OneToMany(mappedBy = "bonus")
	private List<Paymant> paymants;

	public Bonus() {
	}

	public Integer getBonusId() {
		return this.bonusId;
	}

	public void setBonusId(Integer bonusId) {
		this.bonusId = bonusId;
	}

	public BigDecimal getAmount() {
		return this.amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Paymant> getPaymants() {
		return this.paymants;
	}

	public void setPaymants(List<Paymant> paymants) {
		this.paymants = paymants;
	}

	public Paymant addPaymant(Paymant paymant) {
		getPaymants().add(paymant);
		paymant.setBonus(this);

		return paymant;
	}

	public Paymant removePaymant(Paymant paymant) {
		getPaymants().remove(paymant);
		paymant.setBonus(null);

		return paymant;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((amount == null) ? 0 : amount.hashCode());
		result = prime * result + ((bonusId == null) ? 0 : bonusId.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((paymants == null) ? 0 : paymants.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Bonus other = (Bonus) obj;
		if (amount == null) {
			if (other.amount != null)
				return false;
		} else if (!amount.equals(other.amount))
			return false;
		if (bonusId == null) {
			if (other.bonusId != null)
				return false;
		} else if (!bonusId.equals(other.bonusId))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (paymants == null) {
			if (other.paymants != null)
				return false;
		} else if (!paymants.equals(other.paymants))
			return false;
		return true;
	}

}
